
package com.feib.soeasy.job.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Hibernate;
import org.springframework.stereotype.Service;

import com.feib.soeasy.job.dao.ImportDao;
import com.feib.soeasy.job.service.ImportService;
import com.feib.soeasy.model.ColumnValidateError;
import com.feib.soeasy.model.Group;
import com.feib.soeasy.model.MailQueue;
import com.feib.soeasy.model.Payment;
import com.feib.soeasy.model.UploadFile;


/**
 * @title (#)ImportServiceImpl.java<br>
 * @description <br>
 * @author Jimmy Liu<br>
 * @version 1.0.0 2010/11/25
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/11/28 create by Jimmy Liu<br>
 */
@Service("importService")
public class ImportServiceImpl implements ImportService {

    @Resource(name="importDao")
    private ImportDao importDao;
    
    /* (non-Javadoc)
     * @see com.feib.soeasy.service.ImportService#getUnCheckUploadFileByPk(java.lang.Long)
     */
    @Override
    public UploadFile getUnCheckUploadFileByPk(Long uploadFilePk) {
        UploadFile result = this.importDao.queryUploadFileByPk(uploadFilePk);
        if (null != result)
        {
            Hibernate.initialize(result.getFormatDefinition().getColumnDefinitions());
            Hibernate.initialize(result.getFormatDefinition().getCommissionCodeTables());
        }
        return result;
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.ImportService#getFirstUnCheckUploadFile()
     */
    @Override
    public UploadFile getFirstUnCheckUploadFile() {
        UploadFile result = this.importDao.queryFirstUnCheckUploadFile();
        if (null != result)
        {
            Hibernate.initialize(result.getFormatDefinition().getColumnDefinitions());
            Hibernate.initialize(result.getFormatDefinition().getCommissionCodeTables());
        }
        return result;
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.ImportService#updateUploadFileStatus(com.feib.soeasy.model.UploadFile)
     */
    @Override
    public void updateUploadFileStatus(UploadFile uploadFile) {
        this.importDao.updateUploadFileStatus(uploadFile);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.ImportService#deletePaymentsByUploadFile(com.feib.soeasy.model.UploadFile)
     */
    @Override
    public void deletePaymentsByUploadFile(UploadFile uploadFile) {
        this.importDao.deletePaymentsByUploadFile(uploadFile);

    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.ImportService#addPayments(java.util.List)
     */
    @Override
    public void addPayments(List<Payment> payments) {
        this.importDao.addPayments(payments);

    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.ImportService#addColumnValidateErrors(java.util.List)
     */
    @Override
    public void addColumnValidateErrors(List<ColumnValidateError> columnValidateErrors) {
        this.importDao.addColumnValidateErrors(columnValidateErrors);

    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.service.ImportService#hasVirtualAccount(java.lang.String, java.util.Date)
     */
    @Override
    public boolean hasVirtualAccount(String virtualAccount, Date payDue) {
        
        return this.importDao.isDuplicateVirtualAccount(virtualAccount, payDue);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.job.service.ImportService#addMailQueue(com.feib.soeasy.model.MailQueue)
     */
    @Override
    public MailQueue addMailQueue(MailQueue mailQueue) {
        
        mailQueue.setMailStatus(new Integer(0)); // 待發送
        mailQueue.setInQueueDate(new Date());
        return importDao.addMailQueue(mailQueue);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.job.service.ImportService#getColumnValidateErrors(com.feib.soeasy.model.UploadFile)
     */
    @Override
    public List<ColumnValidateError> getColumnValidateErrors(UploadFile uploadFile) {
        
        return importDao.getColumnValidateErrors(uploadFile);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.job.service.ImportService#getConfirmUserEmail(com.feib.soeasy.model.Group)
     */
    @Override
    public List<String> getConfirmUserEmail(Group group) {
        return importDao.getConfirmUserEmail(group);
    }

    /* (non-Javadoc)
     * @see com.feib.soeasy.job.service.ImportService#updateUploadFileTotals(com.feib.soeasy.model.UploadFile)
     */
    @Override
    public void updateUploadFileTotals(UploadFile uploadFile) {
        this.importDao.updateUploadFileTotals(uploadFile);
        
    }

    

}
